'''Module responsible for measuring statistics on the current machine.'''
import measure
stats = {'disk':measure.disk_space, 
         'uptime':measure.uptime,
         'load':measure.cpu_load,
	   'num_cores':measure.num_cores,
	   'num_cpus':measure.num_cpus,
	   'avg_cpu_freq':measure.avg_cpu_freq,
	   'boot_time':measure.boot_time,
	   'memory':measure.memory,
	   'java':measure.java}

cache = {} #

def gather():
    '''Gathers statistics about current machine. 

Returns a dictionary of key:value pairs. Keys are strings indicating type of 
statistic, values are string data. First call to the function will gather all
possible stats: successive ones will only return stats that changed since the
last call.
    '''
    results = {}

    for name in stats:
        # measure statistic
        value = str(stats[name]())
        # check if it changed, move on to next statistic if it didn't
        if name in cache:
            if cache[name]==value: continue 
        # record statistic
        results[name] = cache[name] = value

    return results

